package com.songlanyun.modules.article.controller.admin;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.article.entity.ArticleCourseClassify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.article.service.ArticleCourseClassifyService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;


/**
 * 文章课程分类表
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2021-03-01 14:12:17
 */
@RestController
@RequestMapping("admin/article/course/classify")
public class ArticleCourseClassifyAdminController {
    @Autowired
    private ArticleCourseClassifyService articleCourseClassifyService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("article:articlecourseclassify:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = articleCourseClassifyService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 下拉
     */
    @GetMapping("/select")
    //@RequiresPermissions("article:articlecourseclassify:list")
    public R select() {
        List<ArticleCourseClassify> list = articleCourseClassifyService.list(
                new LambdaQueryWrapper<ArticleCourseClassify>()
                .orderByAsc(ArticleCourseClassify::getOrderIndex)
                .orderByDesc(ArticleCourseClassify::getCreateTime)
        );

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("article:articlecourseclassify:info")
    public R info(@PathVariable("id") Long id) {
        ArticleCourseClassify articleCourseClassify = articleCourseClassifyService.getById(id);

        return R.ok().put("data", articleCourseClassify);
    }

    /**
     * 保存
     */
    @SysLog("保存课程分类")
    @PostMapping("/save")
    //@RequiresPermissions("article:articlecourseclassify:save")
    public R save(@RequestBody ArticleCourseClassify articleCourseClassify) {
        ValidatorUtils.validateEntity(articleCourseClassify);
        articleCourseClassifyService.add(articleCourseClassify);

        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改课程分类")
    @PutMapping("/update")
    //@RequiresPermissions("article:articlecourseclassify:update")
    public R update(@RequestBody ArticleCourseClassify articleCourseClassify) {
        ValidatorUtils.validateEntity(articleCourseClassify);
        articleCourseClassifyService.edit(articleCourseClassify);

        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除课程分类")
    @DeleteMapping("/delete/{id}")
    //@RequiresPermissions("article:articlecourseclassify:delete")
    public R delete(@PathVariable("id") Long id) {
        articleCourseClassifyService.del(id);

        return R.ok();
    }

}
